package com.platform.modules.app.controller;


import com.alibaba.fastjson.JSONObject;
import com.platform.annotation.IgnoreAuth;
import com.platform.annotation.LoginUser;
import com.platform.common.utils.Constant;
import com.platform.common.utils.RestResponse;
import com.platform.modules.app.service.PayChannelUtil;
import com.platform.modules.mall.entity.MallOrderEntity;
import com.platform.modules.mall.entity.MallUserEntity;
import com.platform.modules.sys.service.SysConfigService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

@Slf4j
@Api(tags = "AppZhPayController|综合支付")
@RestController
@RequestMapping("/app/zh/pay")
public class AppZhPayController {

    @Autowired
    private PayChannelUtil payChannelUtil;

    /**
     * 统一下单支付
     */
    @PostMapping("prepay")
    @ApiOperation(value = "商品统一下单请求", notes = "商品统一下单请求")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "body", name = "jsonParam", value = "JSON格式参数", examples = @Example({
                    @ExampleProperty(mediaType = "orderId", value = "orderId"),
                    @ExampleProperty(mediaType = "tradeType", value = "JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付")
            }), required = true, dataType = "string")
    })
    public RestResponse payPrepay(@LoginUser MallUserEntity loginUser, @RequestBody JSONObject jsonParam) {
        return payChannelUtil.pay(loginUser,jsonParam);
    }

    /**
     * 退款
     */
    @GetMapping("refund")
    @ApiOperation(value = "退款", notes = "订单退款请求")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单ID", required = true, dataType = "int", example = "1")
    })
    public RestResponse refund(@LoginUser MallUserEntity loginUser, String orderId) {
        return payChannelUtil.refund(orderId,loginUser.getId());
    }

    /**
     * 二维码支付
     */
    @ApiOperation(value = "获取支付二维码")
    @PostMapping("/generateQrCode")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "body", name = "jsonParam", value = "JSON格式参数", examples = @Example({
                    @ExampleProperty(mediaType = "orderId", value = "orderId"),
                    @ExampleProperty(mediaType = "tradeType", value = "JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付")
            }), required = true, dataType = "string")
    })
    public RestResponse generateQrCode(@LoginUser MallUserEntity loginUser, @RequestBody JSONObject jsonParam) throws Exception {

        return null;
    }

    /**
     * 扫码结果查询
     */
    @ApiOperation(value = "查询扫码结果")
    @GetMapping("/queryQrCode")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "用户token", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单ID", required = true, dataType = "int", example = "1")
    })
    public RestResponse queryQrCode(@LoginUser MallUserEntity loginUser, String orderId) throws Exception {

        return null;
    }



}
